//
//  BIDFavorableInfoView.m
//  HJGJCommunity
//
//  Created by mal on 2017/6/12.
//  Copyright © 2017年 mal. All rights reserved.
//

#import "BIDFavorableInfoView.h"
#import "BIDShowPhotoView.h"
#import "AppDelegate+StaticMethod.h"

@implementation BIDFavorableInfoView

- (void)awakeFromNib
{
    [super awakeFromNib];
}

- (CGFloat)adjustLayoutWithDic:(NSDictionary *)dic
{
    _shopNameLabel.text = @"商铺名称";
    _timeLabel.text = dic[@"createTime"];
    _contentLabel.text = dic[@"title"];
    CGFloat height = [BIDGlobalMethods getHeightWithString:dic[@"title"] font:_shopNameLabel.font constraintSize:CGSizeMake(CGRectGetWidth(self.frame), MAXFLOAT)];
    _heightForContentLabelConstraint.constant = height;
    //
    NSMutableArray *filePathArr = [NSMutableArray array];
    NSArray *arr = dic[@"fileList"];
    if(arr.count > 0)
    {
        for(NSDictionary *subDic in arr)
        {
            NSString *strFilePath = [[NSString alloc] initWithFormat:@"%@/%@", [AppDelegate getServerAddr], subDic[@"path"]];
            [filePathArr addObject:strFilePath];
        }
        [_showPhotoView adjustLayoutWithImgPathArr:filePathArr];
        _heightForShowPhotoViewConstraint.constant = [BIDShowPhotoView heightForShowPhotoViewWithImgCount:arr.count andViewWidth:CGRectGetWidth(self.frame)];
    }
    else
    {
        _heightForShowPhotoViewConstraint.constant = 0.f;
        //[self removeConstraint:_topForTimeLabelConstraint];
        //NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:_timeLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:_contentLabel attribute:NSLayoutAttributeBottom multiplier:1.f constant:8.f];
        //[self addConstraint:constraint];
    }
    [self setNeedsLayout];
    [self layoutIfNeeded];
    height = CGRectGetMaxY(_timeLabel.frame);
    NSLog(@"%f", height+8);
    self.frame = CGRectMake(0, 0, CGRectGetWidth(self.frame), height+8);
    return height+8;
}


@end
